package com.shanzmoo.admin.web;

import com.shanzmoo.base.bean.PageRespBase;
import com.shanzmoo.base.bean.SHttpResponse;
import com.shanzmoo.base.bean.SResponse;
import com.shanzmoo.core.manager.RootGroupManager;
import com.shanzmoo.db.personnel.entity.dto.RootGroupQueryDto;
import com.shanzmoo.db.personnel.entity.dto.RootGroupSaveDto;
import com.shanzmoo.db.personnel.entity.dto.RootGroupUpdateDto;
import com.shanzmoo.db.personnel.entity.vo.RootGroupPageVo;
import com.shanzmoo.db.personnel.entity.vo.RootGroupSelectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 刷机组 前端控制器
 * </p>
 *
 * @author Gzhao
 * @since 2020-12-15
 */
@Api(tags = "人员-刷机组管理")
@RestController
@RequestMapping("/api/rootGroup")
public class RootGroupController {

    @Autowired
    private RootGroupManager rootGroupManager;

    @ApiOperation(value = "添加")
    @PostMapping("/add")
    public SHttpResponse<Boolean> add(@Valid @RequestBody RootGroupSaveDto saveDto) {
        SResponse<Boolean> re = rootGroupManager.add(saveDto);
        return SHttpResponse.transform(re);
    }

    @ApiOperation(value = "修改")
    @PostMapping("/update")
    public SHttpResponse<Boolean> update(@Valid @RequestBody RootGroupUpdateDto updateDto) {
        SResponse<Boolean> re = rootGroupManager.edit(updateDto);
        return SHttpResponse.transform(re);
    }

    @ApiOperation(value = "分页列表")
    @PostMapping("/pageList")
    public SHttpResponse<PageRespBase<RootGroupPageVo>> pageList(@Valid @RequestBody RootGroupQueryDto queryDto) {
        SResponse<PageRespBase<RootGroupPageVo>> re = rootGroupManager.getPageList(queryDto);
        return SHttpResponse.transform(re);
    }

    @ApiOperation(value = "禁用")
    @GetMapping("/disable")
    public SHttpResponse<Boolean> disable(@ApiParam(value = "刷机组id") @RequestParam("id") Integer id) {
        SResponse<Boolean> re = rootGroupManager.disableById(id);
        return SHttpResponse.transform(re);
    }

    @ApiOperation(value = "订单分配选择列表")
    @GetMapping("/selectList")
    public SHttpResponse<List<RootGroupSelectVo>> orderAllotSelectList() {
        SResponse<List<RootGroupSelectVo>> re = rootGroupManager.orderAllotSelectList();
        return SHttpResponse.transform(re);
    }

}
